//    Copyright (C) Kherty.  All rights reserved.
using System.Windows;
using System.Windows.Input;

namespace OpenLS.Spreadsheet.UI
{
    static class GridCalculations
    {
        internal static void EnableCommands(UIElement g)
        {
            g.CommandBindings.Add(new CommandBinding(SpreadsheetCommands.CalculateWorksheet,
                OnCalculateWorksheet, WorksheetHelper.OnHasSelection));

            g.InputBindings.Add(new InputBinding(SpreadsheetCommands.CalculateWorksheet, new KeyGesture(Key.F9, ModifierKeys.Shift)));
            g.CommandBindings.Add(new CommandBinding(SpreadsheetCommands.CalculateWorkbook,
                OnCalculateWorkbook, WorksheetHelper.OnHasSelection));
            g.CommandBindings.Add(new CommandBinding(SpreadsheetCommands.SetCalculationMode,
                OnSetCalculationMode, WorksheetHelper.OnHasSelection));
            g.InputBindings.Add(new InputBinding(SpreadsheetCommands.CalculateWorkbook, new KeyGesture(Key.F9)));
        }
        private static void OnCalculateWorksheet(object sender, ExecutedRoutedEventArgs args)
        {
            SpreadsheetElement.GetWorksheet(sender).Calculate();
        }
        private static void OnCalculateWorkbook(object sender, ExecutedRoutedEventArgs args)
        {
            SpreadsheetElement.GetWorksheet(sender).Workbook.Calculate();
        }
        static void OnSetCalculationMode(object sender, ExecutedRoutedEventArgs args)
        {
            SpreadsheetElement.GetWorksheet(sender).Workbook.CalculationProperties.CalculationMode = (CalculationMode)args.Parameter;
        }

    }
}
